import { http } from '../../utils/net'
Page({
  data: {
    topStepArr:["1.支付信息", "2.通道选择", "3.收款信息"],
    creditCardList: [],
    cloudSwiperRecord:[],
    currentCreditCard:null,
    outMoney: "500.0",
    myActionSheet:null
  },
  getUserCreditCardList() {
    http({
      url: '/api/index/index?method=credit_card_list',
      isShowLoading:true,
      successCb:(res) => {
        console.log(res.data)
        if(res.data.length > 0) {
          this.setData({
            currentCreditCard: res.data[0],
            creditCardList: res.data
          })
        }
      }
    })
  },
  getCloudSwiperRecord() {
    http({
      url:"/api/index/index?method=cloud_brush_list",
      data: {
        page: 1,
        size: 5
      },
      successCb:(res) => {
        console.log(res.data)
        this.setData({
          cloudSwiperRecord: res.data.data
        })
      }
    })
  },
  toSelectCreditCard() {
    this.selectComponent("#myActionSheet").open()
  },
  selectCard(event) {
    console.log(event.currentTarget.dataset.hi)
    this.setData({
      currentCreditCard: event.currentTarget.dataset.hi
    })
    this.selectComponent("#myActionSheet").close()
  },
  toStep2() {
    if(!this.data.outMoney || !this.data.currentCreditCard) {
      wx.showToast({
        title: '请填写完整',
        icon: "none"
      })
      return
    }
    wx.navigateTo({
      url: "/pages/cloudSwiperStep2/index",
      success: (res) => {
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          cardInfo: this.data.currentCreditCard,
          money: this.data.outMoney
        })
      }
    })
  },
  onLoad: function (options) {
    this.getUserCreditCardList()
    this.getCloudSwiperRecord()
  },
  onPullDownRefresh: function () {
    this.getUserCreditCardList()
    this.getCloudSwiperRecord()
  }
})